package com.eastfair.pay.enums;

import com.eastfair.annotation.base.BaseEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.Getter;

import java.util.stream.Stream;

/**
 * <p>
 * 实体注释中生成的类型枚举
 * 发票
 * </p>
 *
 * @author gj
 * @date 2022-06-21
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "InvoiceBusinessTypeEnum", description = "开票来源类型#{H:合同;J:结算单;-枚举")
public enum InvoiceBusinessTypeEnum implements BaseEnum {

    /**
     * H="合同"
     */
    H("合同"),
    /**
     * J="结算单"
     */
    J("结算单"),
    ;

    @ApiModelProperty(value = "描述")
    private String desc;


    /**
     * 根据当前枚举的name匹配
     */
    public static InvoiceBusinessTypeEnum match(String val, InvoiceBusinessTypeEnum def) {
        return Stream.of(values()).parallel().filter(item -> item.name().equalsIgnoreCase(val)).findAny().orElse(def);
    }

    public static InvoiceBusinessTypeEnum get(String val) {
        return match(val, null);
    }

    public boolean eq(InvoiceBusinessTypeEnum val) {
        return val != null && eq(val.name());
    }

    @Override
    @ApiModelProperty(value = "编码", allowableValues = "H,J", example = "H")
    public String getCode() {
        return this.name();
    }

}
